package fr.mywiki.model.ejbAdapter.services;

import javax.ejb.CreateException;
import javax.ejb.EJBException;
import javax.ejb.FinderException;
import javax.ejb.ObjectNotFoundException;
import javax.ejb.SessionBean;

import fr.mywiki.business.account.AccountLite;
import fr.mywiki.business.entry.EntryLite;
import fr.mywiki.business.structure.StructureLite;
import fr.mywiki.business.versioning.VersionLite;
import fr.mywiki.model.ejbAdapter.EntityHomeCache;
import fr.mywiki.model.ejbAdapter.ServicesAdapter;
import fr.mywiki.model.ejbAdapter.services.business.GetLiteServiceBusiness;


/**
 * This session bean deals with adding links to bean objects.
 * 
 * @ejb.bean name = "GetLiteService"
 * 		display-name = "GetLiteService"
 * 		description = "GetLite Administration Service"
 * 		jndi-name = "ejb/MyWiki/GetLiteService"
 * 		remote-business-interface = "fr.mywiki.model.ejbAdapter.services.business.GetLiteServiceBusiness"
 *  
 * @ejb.home
 * 		extends = "javax.ejb.EJBHome"
 * 		package = "fr.mywiki.model.ejbAdapter.services"
 *  
 * @ejb.interface
 * 		extends = "javax.ejb.EJBObject"
 * 		package = "fr.mywiki.model.ejbAdapter.services" 
 *  
 * @author tlombard
 */
public class GetLiteServiceBean extends ServicesAdapter implements GetLiteServiceBusiness,SessionBean {
	/**
	 * The serial version UID.
	 */
	private static final long serialVersionUID = 1L;

	/**
	 * Default create method
	 * @throws CreateException
	 * @ejb.create-method 
	 */
	public void ejbCreate() throws CreateException {
	}
	
	/**
	 * Returns the <code>AccountLite</code> object corresponding to the bean having the given
	 * identifier.
	 * 
	 * @param memberId a <code>Long</code> object identifier.
	 * @return a <code>AccountLite</code> object.
	 * @throws ObjectNotFoundException if the member could not be found in the database.
	 * 
	 * @ejb:interface-method view-type="local"
	 */
	public AccountLite getAccountLite(Long memberId) throws ObjectNotFoundException {
		try {
			return EntityHomeCache.getInstance().getAccountHome().findByPrimaryKey(memberId)
					.getAccountLite();
		} catch (FinderException e) {
			if (e.getClass() == ObjectNotFoundException.class)
				throw (ObjectNotFoundException) e;
			throw new EJBException(e);
		}
	}
	
	/**
	 * Returns the <code>EntryLite</code> object corresponding to the bean having the given
	 * identifier.
	 * 
	 * @param entryId a <code>Long</code> object identifier.
	 * @return a <code>EntryLite</code> object.
	 * @throws ObjectNotFoundException if the right entry could not be found in the database.
	 * 
	 * @ejb:interface-method view-type="local"
	 */
	public EntryLite getEntryLite(Long entryId) throws ObjectNotFoundException {
		try {
			return EntityHomeCache.getInstance().getEntryHome().findByPrimaryKey(entryId)
					.getEntryLite();
		} catch (FinderException e) {
			if (e.getClass() == ObjectNotFoundException.class)
				throw (ObjectNotFoundException) e;
			throw new EJBException(e);
		}
	}
	
	/**
	 * Returns the <code>StructureLite</code> object corresponding to the bean having the given
	 * identifier.
	 * 
	 * @param structureId a <code>Long</code> object identifier.
	 * @return a <code>StructureLite</code> object.
	 * @throws ObjectNotFoundException if the right structure could not be found in the database.
	 * 
	 * @ejb:interface-method view-type="local"
	 */
	public StructureLite getStructureLite(Long structureId) throws ObjectNotFoundException {
		try {
			return EntityHomeCache.getInstance().getStructureHome().findByPrimaryKey(structureId)
					.getStructureLite();
		} catch (FinderException e) {
			if (e.getClass() == ObjectNotFoundException.class)
				throw (ObjectNotFoundException) e;
			throw new EJBException(e);
		}
	}
	
	/**
	 * Returns the <code>VersionLite</code> object corresponding to the bean having the given
	 * identifier.
	 * 
	 * @param versionId a <code>Long</code> object identifier.
	 * @return a <code>VersionLite</code> object.
	 * @throws ObjectNotFoundException if the right version could not be found in the database.
	 * 
	 * @ejb:interface-method view-type="local"
	 */
	public VersionLite getVersionLite(Long versionId) throws ObjectNotFoundException {
		try {
			return EntityHomeCache.getInstance().getVersionHome().findByPrimaryKey(versionId)
					.getVersionLite();
		} catch (FinderException e) {
			if (e.getClass() == ObjectNotFoundException.class)
				throw (ObjectNotFoundException) e;
			throw new EJBException(e);
		}
	}
}
